﻿<UserControl x:Class="Core.Views.Accueil"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:helpers="clr-namespace:Helpers;assembly=Helpers"
             d:DesignHeight="300"
             d:DesignWidth="300"
             mc:Ignorable="d">
    <UserControl.Resources>
        <DataTemplate x:Key="AccueilModuleTemplate">

            <Border Margin="20"
                    Background="White"
                    BorderBrush="{DynamicResource BrushBorderModule}"
                    BorderThickness="1"
                    CornerRadius="{DynamicResource CornerRadiusSize}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <!--  Titre  -->
                    <Border Grid.Row="0"
                            Grid.Column="0"
                            Background="{DynamicResource ColorThemeBrush}"
                            Padding="10,5,10,5">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Row="0"
                                       Grid.Column="0"
                                       Margin="5,0,0,0"
                                       VerticalAlignment="Center"
                                       FontFamily="Segoe UI Light"
                                       FontSize="14"
                                       Foreground="White"
                                       Text="{Binding Libelle}" />

                            <Button Grid.Column="1"
                                    Width="18"
                                    Height="18"
                                    VerticalAlignment="Center"
                                    Command="{Binding RefreshCommand}"
                                    CommandParameter="{Binding UserControl}"
                                    Content="refresh"
                                    Cursor="Hand"
                                    ToolTip="{helpers:Localize Generic_Refresh}" Margin="30,0,0,0">
                                <Button.Template>
                                    <ControlTemplate TargetType="Button">
                                        <Border Width="18"
                                                Height="18"
                                                Background="Transparent">
                                            <Canvas Width="18"
                                                    Height="18"
                                                    HorizontalAlignment="Left"
                                                    VerticalAlignment="Top"
                                                    UseLayoutRounding="False">
                                                <Canvas Canvas.Left="1.371"
                                                        Canvas.Top="0.5"
                                                        Width="13.539"
                                                        Height="16.001">
                                                    <Path x:Name="Path"
                                                          Canvas.Left="0"
                                                          Canvas.Top="0"
                                                          Width="13.539"
                                                          Height="16.001"
                                                          Data="F1M6.769,12.617C9.11,12.617,11.043,10.875,11.344,8.617L13.511,8.617C13.201,12.067 10.301,14.769 6.769,14.769 4.83,14.769 3.08,13.954 1.846,12.647L1.846,16.001 0,14.154 0,9.232 4.923,9.232 6.769,11.078 3.33,11.078C4.175,12.021,5.402,12.617,6.769,12.617 M6.769,1.231C8.709,1.231,10.458,2.048,11.692,3.355L11.692,0 13.539,1.847 13.539,6.77 8.616,6.77 6.769,4.923 10.209,4.923C9.365,3.979 8.137,3.385 6.769,3.385 4.43,3.385 2.496,5.127 2.195,7.385L0.028,7.385C0.338,3.934,3.238,1.231,6.769,1.231"
                                                          Fill="White" />
                                                </Canvas>
                                            </Canvas>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsPressed" Value="true">
                                                <Setter TargetName="Path" Property="Fill" Value="{DynamicResource BrushBackgroundOverButtons}" />
                                            </Trigger>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter TargetName="Path" Property="Fill" Value="{DynamicResource BrushForegroundPressedButtons}" />
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>
                        </Grid>
                    </Border>

                    <!--  Contenu  -->
                    <ContentPresenter Grid.Row="1" Content="{Binding UserControl}" />
                </Grid>
            </Border>
        </DataTemplate>

        <Style x:Key="ListBoxWrapPanel" TargetType="ListBox">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="SnapsToDevicePixels" Value="true" />
            <Setter Property="ItemContainerStyle" Value="{StaticResource ItemTransparentWithNoCursor}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                        <Border Name="Border"
                                Background="{TemplateBinding Background}"
                                BorderBrush="Transparent"
                                BorderThickness="0"
                                CornerRadius="0">
                            <ScrollViewer Margin="0"
                                          Focusable="false"
                                          HorizontalScrollBarVisibility="Disabled"
                                          VerticalScrollBarVisibility="Auto">
                                <WrapPanel HorizontalAlignment="Left" IsItemsHost="True" />
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
            </Style.Resources>
        </Style>
    </UserControl.Resources>

    <controls:MetroContentControl>
        <ListBox x:Name="ResultBox"
                 Margin="50"
                 VerticalContentAlignment="Stretch"
                 ItemTemplate="{StaticResource AccueilModuleTemplate}"
                 ItemsSource="{Binding Path=ModulesAccueil}"
                 ScrollViewer.CanContentScroll="False"
                 Style="{StaticResource ListBoxWrapPanel}"
                 Visibility="{Binding Path=ModulesAccueil.Count,
                                      Converter={StaticResource CountPositiveValueToVisibility}}" />
    </controls:MetroContentControl>
</UserControl>
